package com.chuanshiyidao.huawei;

import android.webkit.JavascriptInterface;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

public class H5ToNative {

    private  GameCallback callback;

    public H5ToNative(GameCallback callback){
        this.callback = callback;
    }

    @JavascriptInterface
    public void payPurch(String data) {
        Utils.log( "data = " + data);
        JSONObject goods = null;
        try {
            goods = new JSONObject(data);
            Object goodsId = goods.get("goodsId");
            HashMap map = new HashMap<String, String>();
            map.put("goodsId", goodsId.toString());
            callback.callback(0, "", map);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @JavascriptInterface
    public void logoutAccount() {
        callback.callback(1, "", new HashMap<String, String>());
    }

    @JavascriptInterface
    public void webPurch(String data) {
        callback.callback(2, data, new HashMap<String, String>());
    }
}
